import 'package:fl_location/fl_location.dart';
import 'package:gold/base/list_view_model.dart';
import 'package:gold/model/gold_recover_shop_model.dart';
import 'package:gold/utils/geocode/geocode_entity.dart';
import 'package:gold/utils/xfg_utils.dart';

/// @description:
/// @author tangzhentao
/// @created at 23:31 2025/3/5

class OfflineDetailViewmodel extends ListViewModel<GoldRecoverShopModel> {
  /// 定位信息
  GeocodeEntity? _location;

  OfflineDetailViewmodel(super.api);

  /// 获取定位信息
  Future getLocation() async {
    final location = await FlLocation.getLocation();
    _location = await geocodeCoordinate(location.latitude, location.longitude);
    if (_location != null) {
      firstLoad();
    } else {
      setFailed(msg: '获取定位失败，请点击重试');
    }
  }

  @override
  onRetry() {
    if (_location != null) {
      firstLoad();
    } else {
      getLocation();
    }
  }

  @override
  Map<String, dynamic>? onOtherData() {
    return {
      "filter": {
        "keywords": '',
        "city": _location?.city,
        'lat': _location?.latitude,
        'lng': _location?.longitude,
      },
    };
  }
}
